﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using System.Linq;
using System.Text;
using com.qt.lib.domain.Entity;

namespace com.qt.lib.domain.Concrete
{
    public class DefaultContext:DbContext
    {
        public DbSet<Customer> Customers { get; set; }

        public DbSet<ProductInfo> ProductInfos { get; set; }

        public DbSet<Order> Orders { get; set; }

        public DbSet<OrderItem> OrderItems { get; set; } 

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();

            modelBuilder.Entity<Order>()
               .HasMany(p => p.OrderItems).WithRequired(p => p.Order);

            modelBuilder.Entity<OrderItem>()
               .HasRequired(p=>p.ProductInfo);
        }
    }
}
